/**
 * Copyright (c) 2013 onionframework.org
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 */
package org.onionframework.core.components;

import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;

import com.thoughtworks.xstream.annotations.XStreamAsAttribute;

/**
 * 配置定义
 * @author allan
 *
 */
public class ConfigDefinition {

	@XStreamAsAttribute private String id;
	@XStreamAsAttribute private String name;
	private String description;
	@XStreamAsAttribute private boolean required = false;
	@XStreamAsAttribute private String defaultValue;
	@XStreamAsAttribute private String type;
	@XStreamAsAttribute private boolean needRestart = false;
	@XStreamAsAttribute  PositionType position = PositionType.any;
		
	/**
	 * @return the id
	 */
	public String getId() {
		return id;
	}

	/**
	 * @param id the id to set
	 */
	public void setId(String id) {
		this.id = id;
	}

	/**
	 * @return the name
	 */
	public String getName() {
		return name;
	}
	
	/**
	 * @param name the name to set
	 */
	public void setName(String name) {
		this.name = name;
	}

	/**
	 * @param description the description to set
	 */
	public void setDescription(String description) {
		this.description = description;
	}

	/**
	 * @param required the required to set
	 */
	public void setRequired(boolean required) {
		this.required = required;
	}

	/**
	 * @param defaultValue the defaultValue to set
	 */
	public void setDefaultValue(String defaultValue) {
		this.defaultValue = defaultValue;
	}

	/**
	 * @param type the type to set
	 */
	public void setType(String type) {
		this.type = type;
	}

	/**
	 * @param needRestart the needRestart to set
	 */
	public void setNeedRestart(boolean needRestart) {
		this.needRestart = needRestart;
	}

	/**
	 * @param positionType the positionType to set
	 */
	public void setPosition(PositionType position) {
		this.position = position;
	}

	/**
	 * @return the description
	 */
	public String getDescription() {
		return description;
	}
	
	/**
	 * @return the required
	 */
	public boolean isRequired() {
		return required;
	}
	
	/**
	 * @return the defaultValue
	 */
	public String getDefaultValue() {
		return defaultValue;
	}
	
	/**
	 * @return the type
	 */
	public String getType() {
		return type;
	}
	
	/**
	 * @return the needReStart
	 */
	public boolean isNeedRestart() {
		return needRestart;
	}
	
	/**
	 * @return the positionType
	 */
	public PositionType getPosition() {
		return position;
	}



	public static enum PositionType{
		file("文件"),db("数据库"),any("任意");
		
		private String title;

		private PositionType(String title) {
			this.title = title;
		}

		/**
		 * @return the title
		 */
		public String getTitle() {
			return title;
		}
	}
	
	public String toString(){
		return new ToStringBuilder(this,ToStringStyle.SHORT_PREFIX_STYLE)
			.append("id", this.id)
			.append("name", this.name)
			.append("type",this.type).toString();
	}
}
